﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Renci.iRods;
using System.Diagnostics;
using System.Data.Common;
using System.Data.SqlClient;
using Renci.iRods.Common;
using System.IO;
using Renci.iRods.Data;
using System.Threading;
using System.Collections.ObjectModel;
using System.Collections;
using System.Data;

namespace Renci.iRods.Test
{
    class Program
    {
        /// <summary>
        /// Mains the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        static void Main(string[] args)
        {
            
            //using (var testFile = File.CreateText(@"C:\Test\ttt.txt")) 
            //{
            //    for (int i = 0; i < 1024 * 1024 * 64 / 8; i++)
            //    {
            //        testFile.Write("ABCDEFGH");
            //    }
            //}


            //var fff = new FileInfo(@"C:\Test\ttt.txt");

            //ConnectionInfo account = new ConnectionInfo("152.54.9.242", "rodstester", "rodstester");
            //ConnectionInfo account = new ConnectionInfo("152.54.9.9", "rods", "rods");
            //ConnectionInfo account = new ConnectionInfo("192.168.56.101", "rods", "rods", "mainResc");
            //ConnectionInfo account = new ConnectionInfo("192.168.10.186", "rods", "rods", "mainResc");
            //ConnectionInfo account = new ConnectionInfo("192.168.56.101", "abcdef", "abcdef");
            ConnectionInfo account = new ConnectionInfo("iren.renci.org", "demouser", "CANDO");
            //ConnectionInfo account = new ConnectionInfo("iren.renci.org", "public", "tmp0211");
            
            //ConnectionInfo account = new ConnectionInfo("152.54.9.242", "aaa1", "234234");
            //ConnectionInfo account = new ConnectionInfo("152.54.9.242", "rodstester", "olegVbZone", "rodstester");

            using (var conn = new IRodsConnection(account))
            {
                conn.Open();

               //var rootItems = from c in conn.Collections
               //                 //where c.FullName == "/"
               //                 select c; 

                var rootItems = from c in conn.Collections
                                //where c.FullName.Contains("m")
                                where c.FullName.Contains("renci")
                                && c.OwnerName == "rodsBoot"
                                select c;

                PrintCollections(rootItems);

                var users = from u in conn.Users
                            where u.Name.StartsWith("j")
                            select u;

                foreach (var user in users)
                {
                    Console.WriteLine(string.Format("{0}\t{1}", user.Name, user.Type));
                }

                conn.Close();
            }

            Console.WriteLine("Press any key...");
            Console.ReadKey();
            return;


            using (var conn = new IRodsConnection(account))
            {
                conn.Open();

                var q = new IRodsQuery();
                q.AddOutputColumn(DataObjectAttributes.COL_COLL_NAME, QueryColumnAction.Descending);
                //q.AddOutputColumn(DataObjectAttributes.COL_META_COLL_ATTR_NAME, QueryColumnAction.Descending);
                //q.AddOutputColumn(DataObjectAttributes.COL_META_COLL_ATTR_VALUE, QueryColumnAction.Descending);
                //q.AddOutputColumn(DataObjectAttributes.COL_DATA_NAME);
                //q.AddOrderBy(DataObjectAttributes.COL_DATA_NAME, QueryColumnAction.Descending);
                //q.AddOutputColumn(DataObjectAttributes.COL_D_DATA_PATH, QueryColumnAction.Count);
                //q.AddOutputColumn(DataObjectAttributes.COL_COLL_USER_NAME);
                //q.AddCondition(DataObjectAttributes.COL_COLL_NAME, "begin_of '/olegVbZone/trash'");
                //q.AddCondition(DataObjectAttributes.COL_COLL_NAME, "parent_of '/olegVbZone'");
                //q.AddCondition(DataObjectAttributes.COL_COLL_NAME, "parent_of '/olegVbZone/trash/home/rods/newdir'");
                //q.AddCondition(DataObjectAttributes.COL_COLL_NAME, "='?'");

                //q.AddCondition(DataObjectAttributes.COL_D_DATA_ID, "<'10060' || >'10070'");
                //q.AddCondition(DataObjectAttributes.COL_D_DATA_ID, "<'10060' || >'10070' && <'10075'");

                //q.PageSize = 3;
                //q.PageIndex = 100;
                var result = conn.ExecuteQuery(q);

                foreach (IDataRecord item in result)
                {
                    Console.WriteLine(item[0]);
                }


                while (result.Read())
                {
                    //foreach (var f in result.Fields)
                    //{
                    //    Console.Write(result.GetString(f) + "\t");
                    //}
                    Console.WriteLine();
                }


                var st = new IRodsStream(conn, "/mainZone/home/rods/testfile.txt", FileMode.Open, FileAccess.Read);
                //st.Seek(-100, SeekOrigin.End);
                //st.Seek(100, SeekOrigin.Begin);
                //st.Seek(100, SeekOrigin.Current);
                //st.Seek(1024 * 1024 * 16 - 100, SeekOrigin.Begin);
                //var buffer = new byte[1024];
                //var read = st.Read(buffer, 0, 1);
                //read = st.Read(buffer, 0, 1);

                var output = Console.OpenStandardOutput();
                var output1 = File.OpenWrite(@"C:\Test\downloaded.txt");
                //conn.AddZone("demozone1", "remote", "", "comment1");
                //conn.AddUser("abcdef", "rodsuser");
                //conn.ModifyUser("abcdef", "password", "abcdef");

                //var collections = conn.Collections.ToList();

                //var collections = conn.Collections.Take(10).ToList();
                //var aa = conn.ObjectAudits.ToList();

                //var collections = (from c in conn.Collections
                //                   where c.Id > 10000
                //                   select c).Take(10);

                //var collections = (from c in conn.Collections
                //                   where c.Id > 503000 && c.Id < 504000
                //                   select c).Take(10);

                //var collections = (from c in conn.Collections
                //                   where c.Id == 503506 || c.Id == 503507 || c.Id == 503508
                //                   select c).Take(10);
                //var cc = new IRodsCollection(conn, "/");
                var file = new IRodsFile(conn, "/mainZone/home/rods/testfile.txt");
                file.Download(output1);
                file.Upload(File.OpenRead(@"C:\Test\ttt1.txt"), true);
                var cc = new IRodsCollection(conn, "/mainZone/home/rods1");
                
                cc.Refresh();


                var collections = (from c in conn.Collections
                                   //where c.FullName.StartsWith("/T")
                                   where c.FullName.Contains("ab")
                                   select c).Take(10);

                PrintIdAndName(collections);

                //  Test collection creation
                //CreateTestCollections(conn);
                //Console.WriteLine("Collections:");
                //foreach (var c in conn.Collections)
                //{
                //    Console.WriteLine(string.Format("Name: {0}\tFull Name: {1}", c.Name, c.FullName));
                //}
                //RemoveTestCollection(conn);

                //  Test files creation
                //CreateTestFiles(conn);
                //DeleteTestFiles(conn);

                //  Test User creation
                //CreateUsers(conn);
                //Console.WriteLine("Users:");
                //foreach (var u in conn.Users)
                //{
                //    Console.WriteLine(string.Format("Name: {0}", u.Name));
                //}
                //DeleteUsers(conn);

                //CreateUserWithMetadata(conn);

                TestMetadata(conn);

                conn.Close();
                //admin>2spass 1231231gCBizHWbwIYyWLoysGzTe6SyzqFKMniZX rodstester 66gpcNS9WfslEFGQP2HE/68Ye8C0iIsSJOmPIYz7qxFU+fK+JtWsq/6olsxLMC/f4341qfBlcwX9HS0/fppHIw==
                //Version 2 scrambled form is:)*#aJa8X+JTqc-d9g3CgIpL&+8%O-CU,o2p,RFM&etzh7wl
                //var rrr = conn.obfEncodeByKeyV2("1231231gCBizHWbwIYyWLoysGzTe6SyzqFKMniZX", "66gpcNS9WfslEFGQP2HE/68Ye8C0iIsSJOmPIYz7qxFU+fK+JtWsq/6olsxLMC/f4341qfBlcwX9HS0/fppHIw==");
                //var works = (rrr == "\"#vgPgEkEjzD)G$M!AQuW$M',9&P.DV-p3q-SGN'fu!V%eT");

                //var result = conn.EncryptPassword("1231231");

                //conn.AddCollectionMetadata("/olegVbZone/home/rodstester/xyz1", "ooo", "yyy");


                //var coll = new MetadataCollection(conn, "/olegVbZone/home/rodstester/xyz1", "-c");
                //coll.Refresh();
                //foreach (var item in coll)
                //{
                //    item.Value = DateTime.Now.ToShortTimeString();
                //}
                //coll.SaveChanges();

                //coll.Add(new MetaData("aaa1", "vvv1"));
                ////coll.Add(new MetaData("aaa2", "vvv2"));
                ////coll.Add(new MetaData("aaa3", "vvv3"));
                //coll.SaveChanges();
                //coll.Refresh();
                //var ttt = conn.MetaData.ToList();

                conn.RemoveUnusedMetadata();

                conn.ModifyUser("aaa1#olegVbZone", "password", "345345345");

                //conn.AddCollectionMetadata("/olegVbZone/home/rodstester/xyz1", "ooo", "yyy");
                //conn.ModifyCollectionMetadata("/olegVbZone/home/rodstester/xyz1", "ooo", "567", "789");
                conn.RemoveCollectionMetadata("/olegVbZone/home/rodstester/xyz1", "ooo", "789");

                
                
                //var qq = conn.Quotas.ToList();
                //conn.MakeDir("/olegVbZone/home/rodstester/code_test_1");
                //var rr = conn.Resources.ToList();
                //conn.AddResource("testresc", "unix file system", "archive", "localhost", "/home/oleg/irods_rescource_test");
                //conn.ModifyResource("testresc", "comment", "abc");
                //conn.AddGroup("aaabbb_group");
                //conn.RemoveGroup("aaabbb_group");
                //conn.AddUserToGroup("test", "aaa2");
                //conn.RemoveUserFromGroup("test", "aaa2");
                //conn.AddToken("user_type", "oleg", "value1");
                //conn.RemoveToken("user_type", "oleg", "value2");


                //var localZoneName = conn.LocalZoneName;

                //conn.ExecuteSimpleQuery("select * from R_RESC_MAIN where resc_name=?","olegVbResc");
                //conn.ExecuteSimpleQuery(1, "select token_name from R_TOKN_MAIN");
                //conn.ExecuteSimpleQuery(2, "select token_name from R_TOKN_MAIN");

                //var zones = from z in conn.Zones
                //             //where t.Namespace == "user_type"
                //             select z;

                //var tt = zones.ToList();

                //conn.AddUser("aaab1", "rodsuser");
                //conn.AddUser("aaab2#olegVbZone", "rodsuser");
                //conn.AddUser("aaab3@test#olegVbZone", "rodsuser");
                //conn.AddUser("aaab4@test#olegVbZone", "rodsuser");
                //conn.RemoveUser("aaa#olegVbZone");
                //conn.RemoveUser("aaa@bbb#olegVbZone ");
                //conn.RemoveUser("@ss#olegVbZone ");
                //conn.RemoveUser("aaa1#olegVbZone");
                //conn.RemoveUser("aaa2#olegVbZone ");
                //conn.RemoveUser("aaa3@test#olegVbZone ");
                //conn.RemoveUser("aaab4@test#olegVbZone ");

                //conn.ModifyUser("aaa1#olegVbZone", IRodsConnection.UsernameProperty.Comment, "Test comment");


                var qwe = from f in conn.Files
                          //from c in conn.Collections
                          //where c.Name.StartsWith("aaa")
                          //where f.CollectionName != "/olegVbZone/home/rodstester"
                          where
                              //f.ID  < 10050
                              //f.CollectionName.StartsWith("/olegVbZone/trash")
                              //f.CollectionName.Contains("aaa")
                              //f.CreationTime > DateTime.Now.AddDays(-10)
                                f.ID < 10060 || (f.ID > 10070 && f.Mode == "222") || f.Mode == "333"
                          //f.CollectionName.Length < 10
                          //where c.ParentName == "/"
                          //where f != null
                          //where f.CollectionID == 1231
                          //select f;
                          orderby f.CollectionName
                          select new { Test = f.Path };
                //select c;
                //select new { aaa = f.ID, bbb = c.Id };

                var res = qwe.ToList();
                //var res = qwe.Skip(20).Take(7).ToList();



                //foreach (IRodsDataRecord item in result)
                //{
                //    //var qq = new IRodsQuery();
                //    //qq.AddOutputColumn(DataObjectAttributes.COL_ZONE_NAME);
                //    //var rr = conn.ExecuteQuery(qq);
                //    //foreach (IRodsDataRecord ii in rr)
                //    //{
                //    //    foreach (var ff in rr.Fields)
                //    //    {
                //    //        Console.Write(ii[ff] + "\t");
                //    //    }
                //    //    Console.WriteLine();
                //    //}

                //    Console.WriteLine("==========================");


                //    //foreach (var f in result.Fields)
                //    //{
                //    //    Console.Write( + "\t");
                //    //}
                //    //Console.WriteLine();
                //}


                //q.PageIndex = 1;
                //result = conn.ExecuteQuery(q);

                //foreach (IRodsDataRecord item in result)
                //{
                //    foreach (var f in result.Fields)
                //    {
                //        Console.Write(item[f] + "\t");
                //    }
                //    Console.WriteLine();
                //}


                //conn.WorkingDirectory = "/";
                //var c1 = new IRodsCollection(conn, "/");
                //c1.CreateSubdirectory("xyz1");
                ////c1.CreateSubdirectory("xyz1");
                //var c2 = new IRodsCollection(conn, "xyz1");
                //c2.Delete(true);

                //var f1 = new IRodsFile(conn, "/olegVbZone/home/rodstester/aaa2___");
                //f1.MoveTo("aaa_moved_1");

                //var ff1 = f1.Open(FileMode.Open);
                //var ff2 = f1.Open(FileMode.Open);

                //var f2 = new Data.IRodsFile(conn, "/olegVbZone/home/rodstester/aaa1");
                //var fe = f.Exists;
                //var c = new Data.IRodsCollection(conn, "coll1");
                //var ce = c.Exists;

                //var fs1 = new IRodsStream(conn, "/olegVbZone/home/rodstester/aaa1", FileMode.CreateNew, FileAccess.Write);
                //var fs2 = new IRodsStream(conn, "/olegVbZone/home/rodstester/aaa2", FileMode.Open, FileAccess.Write);
                //var fs3 = new IRodsStream(conn, "/olegVbZone/home/rodstester/aaa3", FileMode.Open, FileAccess.Write);
                using (var fs6 = new IRodsStream(conn, "/olegVbZone/home/rodstester/aaa1", FileMode.Open, FileAccess.Write))
                {
                    Debug.WriteLine(fs6.Handle);
                    using (var fs7 = new IRodsStream(conn, "/olegVbZone/home/rodstester/aaa2", FileMode.Open, FileAccess.Write))
                    {
                        Debug.WriteLine(fs7.Handle);
                    }
                    using (var fs7 = new IRodsStream(conn, "/olegVbZone/home/rodstester/aaa3", FileMode.Open, FileAccess.Write))
                    {
                        Debug.WriteLine(fs7.Handle);
                    }
                }

                conn.Close();

                var filename = "/olegVbZone/home/rodstester/testbig";

                //var file = conn.GetFile(filename);

                //if (file != null)
                //    conn.Delete(file);

                //conn.CreateFile("testfile1", File.OpenRead("C:\\Test\\testascii.txt"));
                //conn.CreateFile(filename, File.OpenRead("C:\\Test\\test3.txt"));

                //var coll = conn.CreateCollection("/olegVbZone/home/rodstester/test5");
                //var coll = conn.GetCollection("/olegVbZone/home/rodstester/test2");
                //conn.Delete(coll);


                //var file = conn.GetFile("demo.gz");
                //conn.Delete(file);

                //var results = conn.Query<Collection>();

                //var cmd = new IRodsCommand(conn);

                //cmd.SelectColumns.Add(DataObjectAttributes.COL_QUOTA_USER_NAME);
                //cmd.SelectColumns.Add(DataObjectAttributes.COL_R_VAULT_PATH);
                //cmd.SelectColumns.Add(DataObjectAttributes.COL_TOKEN_NAME);                
                //cmd.SelectColumns.Add(DataObjectAttributes.COL_USER_NAME);

                //cmd._selectColumns.Add(DataObjectAttributes.COL_COLL_ID);
                //cmd._selectColumns.Add(DataObjectAttributes.COL_COLL_NAME);
                //cmd._selectColumns.Add(DataObjectAttributes.COL_COLL_PARENT_NAME);
                //cmd._selectColumns.Add(DataObjectAttributes.COL_COLL_OWNER_NAME);
                //cmd._selectColumns.Add(DataObjectAttributes.COL_COLL_OWNER_ZONE);
                //cmd._selectColumns.Add(DataObjectAttributes.COL_COLL_MAP_ID);
                //cmd._selectColumns.Add(DataObjectAttributes.COL_COLL_INHERITANCE);
                //cmd._selectColumns.Add(DataObjectAttributes.COL_COLL_COMMENTS);
                //cmd._selectColumns.Add(DataObjectAttributes.COL_COLL_CREATE_TIME);
                //cmd._selectColumns.Add(DataObjectAttributes.COL_COLL_MODIFY_TIME);
                //cmd._selectColumns.Add(DataObjectAttributes.COL_COLL_TYPE);
                //cmd._selectColumns.Add(DataObjectAttributes.COL_COLL_INFO1);
                //cmd._selectColumns.Add(DataObjectAttributes.COL_COLL_INFO2);

                //cmd.SelectColumns.Add(DataObjectAttributes.COL_R_RESC_NAME);

                ////cmd.SelectColumns.Add(DataObjectAttributes.COL_META_DATA_ATTR_VALUE);
                ////cmd.SelectColumns.Add(DataObjectAttributes.COL_META_DATA_ATTR_UNITS);
                ////cmd.SelectColumns.Add(DataObjectAttributes.COL_META_DATA_ATTR_ID);
                ////cmd.SelectColumns.Add(DataObjectAttributes.COL_META_DATA_CREATE_TIME);
                ////cmd.SelectColumns.Add(DataObjectAttributes.COL_META_DATA_MODIFY_TIME);
                ////cmd.SelectColumns.Add(DataObjectAttributes.COL_META_COLL_ATTR_NAME);
                ////cmd.SelectColumns.Add(DataObjectAttributes.COL_META_COLL_ATTR_VALUE);
                ////cmd.SelectColumns.Add(DataObjectAttributes.COL_META_DATA_MODIFY_TIME);
                ////cmd.SelectColumns.Add(DataObjectAttributes.COL_META_COLL_ATTR_UNITS);
                ////cmd.SelectColumns.Add(DataObjectAttributes.COL_META_COLL_ATTR_ID);
                ////cmd.Conditions.Add(new IRodsQueryCondition(DataObjectAttributes.COL_COLL_PARENT_NAME, "='/olegVbZone/home/rods'"));

                //var result = cmd.ExecuteReader<Collection>();

                //while (result.Read())
                //{
                //    foreach (var f in result.Fields)
                //    {
                //        Console.Write(result.GetString(f) + "\t");
                //    }
                //    Console.WriteLine();
                //}
                //SqlDataReader

                //var db = new IRodsDataContext(new SqlQueryProvider(conn, IRodsDataContext.StandardPolicy, Console.Out));
                //string city = "London";

                //var query = from c in db.Collections
                //            orderby c.Name
                //            where
                //               c.ParentName != "/olegVbZone/home/rods"
                //            //                            && c.Name == "/olegVbZone/home/rods/testdir1"
                //            //select new { Name = c.Name, Phone = c.OwnerZone };
                //            //select c.Name;
                //            select c;


                //Debug.WriteLine(string.Format("Query:\n{0}\n", query));

                //var ttt = query.ToList();
                conn.Close();
            }
        }

        private static void PrintCollections(IQueryable<FileSystemDataItem> items)
        {
            foreach (var item in items)
            {
                Console.WriteLine(string.Format("Name: {0}\tCreation Time: {2}\tFullName: {1}", item.Name, item.FullName, item.CreationTime));
            }
        }

        private static void PrintIdAndName(IEnumerable collections)
        {
            foreach (dynamic collection in collections)
            {
                Console.WriteLine("{0}\t- {1}", collection.ID, collection.Name);
            }
        }

        private static void TestMetadata(IRodsConnection conn)
        {
            var col = conn.Collections.First();
            //col.MetaData.Add("colmeta1", "colvalue1");
            //col.MetaData.Add("colmeta2", "colvalue2");
            //col.MetaData.SaveChanges();
            col.MetaData.Refresh();

            var r = conn.Resources.First();
            //r.MetaData.Add("resmeta1", "resvalue1");
            //r.MetaData.Add("resmeta2", "resvalue2");
            //r.MetaData.SaveChanges();
            r.MetaData.Refresh();

            var rg = conn.ResourceGroups.FirstOrDefault();
            //if (rg == null)
            //{
            //    conn.AddResourceToGroup("public", r.Name);
            //    rg = conn.ResourceGroups.First();
            //}
            //rg.MetaData.Add("resgroupmeta1", "resgroupvalue1");
            //rg.MetaData.Add("resgroupmeta2", "resgroupvalue2");
            //rg.MetaData.SaveChanges();
            rg.MetaData.Refresh();

            var u = conn.Users.First();
            //u.MetaData.Add("usermeta1", "uservalue1");
            //u.MetaData.Add("usermeta2", "uservalue2");
            //u.MetaData.SaveChanges();
            u.MetaData.Refresh();

            var f = conn.Files.First();
            //f.MetaData.Add("filemeta1", "filevalue1");
            //f.MetaData.Add("filemeta2", "filevalue2");
            //f.MetaData.SaveChanges();
            f.MetaData.Refresh();

        }

        private static void CreateUserWithMetadata(IRodsConnection conn)
        {
            var username = "metadatauser1";
            var user = (from u in conn.Users where u.Name == username select u).SingleOrDefault();
            if (user == null)
            {
                conn.AddUser(username, "rodsuser");
                user = (from u in conn.Users where u.Name == username select u).SingleOrDefault();
            }
            user.MetaData.Add("name1", "value1");
            user.MetaData.Add("name2", "value2");
            user.MetaData.Add("name3", "value3");
            user.MetaData.SaveChanges();
            foreach (var m in user.MetaData)
            {
                Console.WriteLine("{0}-{1}", m.Name, m.Value);
            }
            //conn.RemoveUser("metadatauser");
        }

        private static void CreateUsers(IRodsConnection conn)
        {
            for (int i = 0; i < 10; i++)
            {
                conn.AddUser(string.Format("user_{0}", i), "rodsuser");
            }
        }

        private static void DeleteUsers(IRodsConnection conn)
        {
            for (int i = 0; i < 10; i++)
            {
                conn.RemoveUser(string.Format("user_{0}", i));
            }
        }

        private static void CreateTestFiles(IRodsConnection conn)
        {
            for (int i = 0; i < 10; i++)
            {
                IRodsFile f = new IRodsFile(conn, string.Format("file_{0}", i));
                f.Create();
            }
        }

        private static void DeleteTestFiles(IRodsConnection conn)
        {
            for (int i = 0; i < 10; i++)
            {
                IRodsFile f = new IRodsFile(conn, string.Format("file_{0}", i));
                f.Delete();
            }
        }

        private static void CreateTestCollections(IRodsConnection conn)
        {
            for (int i = 0; i < 10; i++)
            {
                IRodsCollection c = new IRodsCollection(conn, string.Format("testcollection_{0}", i));
                c.Create();
            }
        }

        private static void RemoveTestCollection(IRodsConnection conn)
        {
            for (int i = 0; i < 10; i++)
            {
                IRodsCollection c = new IRodsCollection(conn, string.Format("testcollection_{0}", i));
                c.Delete();
            }
        }
    }
}


//#define IRODS_STR_PI "str myStr[MAX_NAME_LEN];"
//#define STR_PI "str myStr;" 
//#define STR_PTR_PI "str *myStr;" 
//#define PI_STR_PI "piStr myStr[MAX_NAME_LEN];" 
//#define INT_PI "int myInt;"
//#define BUF_LEN_PI "int myInt;"
//#define DOUBLE_PI "double myDouble;"
//#define RErrMsg_PI "int status; str msg[ERR_MSG_LEN];"
//#define RError_PI "int count; struct *RErrMsg_PI[count];"
//#define RHostAddr_PI "str hostAddr[LONG_NAME_LEN]; str rodsZone[NAME_LEN]; int port; int dummyInt;"
//#define RODS_STAT_T_PI "double st_size; int st_dev; int st_ino; int st_mode; int st_nlink; int st_uid; int st_gid; int st_rdev; int st_atim; int st_mtim; int st_ctim; int st_blksize; int st_blocks;"
//#define RODS_DIRENT_T_PI "int d_offset; int d_ino; int d_reclen; int d_namlen; str d_name[DIR_LEN];" 
//#define KeyValPair_PI "int ssLen; str *keyWord[ssLen]; str *svalue[ssLen];" 
//#define DataOprInp_PI "int oprType; int numThreads; int srcL3descInx; int destL3descInx; int srcRescTypeInx; int destRescTypeInx; double offset; double dataSize; struct KeyValPair_PI;"
//#define CollInp_PI "str collName[MAX_NAME_LEN]; struct KeyValPair_PI;"
//#define SqlResult_PI "int attriInx; int reslen; str *value(rowCnt)(reslen);"  
//#define DataObjInfo_PI "str objPath[MAX_NAME_LEN]; str rescName[NAME_LEN]; str rescGroupName[NAME_LEN]; str dataType[NAME_LEN]; double dataSize; str chksum[NAME_LEN]; str version[NAME_LEN]; str filePath[MAX_NAME_LEN]; str *rescInfo; str dataOwnerName[NAME_LEN]; str dataOwnerZone[NAME_LEN]; int  replNum; int  replStatus; str statusString[NAME_LEN]; double  dataId; double collId; int  dataMapId; int flags; str dataComments[LONG_NAME_LEN]; str dataMode[SHORT_STR_LEN]; str dataExpiry[TIME_LEN]; str dataCreate[TIME_LEN]; str dataModify[TIME_LEN]; str dataAccess[NAME_LEN]; int  dataAccessInx; int writeFlag; str destRescName[NAME_LEN]; str backupRescName[NAME_LEN]; str subPath[MAX_NAME_LEN]; int *specColl; int *next;"
//#define TransStat_PI "int numThreads; double bytesWritten;"
//#define RescGrpInfo_PI "str rescGroupName[NAME_LEN]; str *rescName; int status; int dummy; int *cacheNext; struct *RescGrpInfo_PI;"
//#define AuthInfo_PI "str authScheme[NAME_LEN]; int authFlag; int flag; int ppid; str host[NAME_LEN]; str authStr[NAME_LEN];"
//#define UserOtherInfo_PI "str userInfo[NAME_LEN]; str userComments[NAME_LEN]; str userCreate[TIME_LEN]; str userModify[TIME_LEN];"
//#define UserInfo_PI "str userName[NAME_LEN]; str rodsZone[NAME_LEN]; str userType[NAME_LEN]; int sysUid; struct AuthInfo_PI; struct UserOtherInfo_PI;"
//#define CollInfo_PI "double collId; str collName[MAX_NAME_LEN]; str collParentName[MAX_NAME_LEN]; str collOwnerName[NAME_LEN]; str collOwnerZone[NAME_LEN]; int collMapId; int collAccessInx; str collComments[LONG_NAME_LEN]; str collInheritance[LONG_NAME_LEN]; str collExpiry[TIME_LEN]; str collCreate[TIME_LEN]; str collModify[TIME_LEN]; str collAccess[NAME_LEN]; str collType[NAME_LEN]; str collInfo1[MAX_NAME_LEN]; str collInfo2[MAX_NAME_LEN]; int *next;"
//#define Rei_PI "int status; str statusStr[MAX_NAME_LEN]; str ruleName[NAME_LEN]; int *rsComm;struct *MsParamArray_PI; struct MsParamArray_PI; int l1descInx; struct *DataObjInp_PI; struct *DataObjInfo_PI; struct *RescGrpInfo_PI; struct *UserInfo_PI; struct *UserInfo_PI; struct *CollInfo_PI; struct *UserInfo_PI; struct *KeyValPair_PI; str ruleSet[RULE_SET_DEF_LENGTH]; int *next;" 
//#define ReArg_PI "int myArgc; str *myArgv[myArgc];"
//#define ReiAndArg_PI "struct *Rei_PI; struct ReArg_PI;"
//#define BytesBuf_PI "int buflen; char *buf(buflen);"
//#define BinBytesBuf_PI "int buflen; bin *buf(buflen);"
//#define MsParam_PI "str *label; piStr *type; ?type *inOutStruct; struct *BinBytesBuf_PI;"
//#define MsParamArray_PI "int paramLen; int oprType; struct *MsParam_PI[paramLen];"
//#define TagStruct_PI "int ssLen; str *preTag[ssLen]; str *postTag[ssLen]; str *keyWord[ssLen];" 
//#define ReconnMsg_PI "int status; int cookie; int procState; int flag;"
//#define VaultPathPolicy_PI "int scheme; int addUserName; int trimDirCnt;"
//#define StrArray_PI "int len; int size; str *value(len)(size);" 
//#define IntArray_PI "int len; int *value(len);" 
//#define SubFile_PI "struct RHostAddr_PI; str subFilePath[MAX_NAME_LEN]; int mode; int flags; double offset; struct *SpecColl_PI;" 
//#define XmsgTicketInfo_PI "int sendTicket; int rcvTicket; int expireTime; int flag;"
//#define SendXmsgInfo_PI "int msgNumber; str msgType[HEADER_TYPE_LEN]; int numRcv; int flag; str *msg; int numDel; str *delAddress[numDel]; int *delPort(numDel); str *miscInfo;"
//#define GetXmsgTicketInp_PI "int expireTime; int flag;"
//#define SendXmsgInp_PI "struct XmsgTicketInfo_PI; str sendAddr[NAME_LEN]; struct SendXmsgInfo_PI;"
//#define RcvXmsgInp_PI "int rcvTicket; int msgNumber; int seqNumber; str msgCondition[NAME_LEN];"
//#define RcvXmsgOut_PI "str msgType[HEADER_TYPE_LEN]; str sendUserName[NAME_LEN]; str sendAddr[NAME_LEN]; int msgNumber; int seqNumber; str *msg;"
//#define h5error_PI "str major[MAX_ERROR_SIZE]; str minor[MAX_ERROR_SIZE];"
//#define h5File_PI "int fopID; str *filename; int ffid; struct *h5Group_PI; struct h5error_PI;int ftime;"
//#define h5Group_PI "int gopID; int gfid; int gobjID[OBJID_DIM]; str *gfullpath; int $dummyParent; int nGroupMembers; struct *h5Group_PI(nGroupMembers); int nDatasetMembers; struct *h5Dataset_PI(nDatasetMembers); int nattributes; struct *h5Attribute_PI(nattributes); struct h5error_PI;int gtime;"
//#define h5Dataset_PI "int dopID; int dfid; int dobjID[OBJID_DIM]; int dclass; str *dfullpath; int nattributes; struct *h5Attribute_PI(nattributes); struct h5Datatype_PI; struct h5Dataspace_PI; int nvalue; % dclass:3,6,9 = str *value[nvalue]:default= char *value(nvalue); struct h5error_PI;int dtime;"
//#define h5Attribute_PI "int aopID; int afid; str *aname; str *aobj_path; int aobj_type; int aclass; struct h5Datatype_PI; struct h5Dataspace_PI; int nvalue; % aclass:3,6,9 = str *value[nvalue]:default= char *value(nvalue); struct h5error_PI;"
//#define h5Datatype_PI "int tclass; int torder; int tsign; int tsize; int ntmenbers; int *mtypes(ntmenbers); str *mnames[ntmenbers];"
//#define h5Dataspace_PI "int rank; int dims[H5S_MAX_RANK]; int npoints; int start[H5DATASPACE_MAX_RANK]; int stride[H5DATASPACE_MAX_RANK]; int count[H5DATASPACE_MAX_RANK];"
//#define CollEnt_PI "int objType; int replNum; int replStatus; int dataMode; double dataSize; str $collName; str $dataName; str $dataId; str $createTime; str $modifyTime; str $chksum; str $resource; str $rescGrp; str $phyPath; str $ownerName; struct SpecColl_PI;" 
//#define RuleStruct_PI "int maxNumOfRules; str *ruleBase[maxNumOfRules]; str *action[maxNumOfRules]; str *ruleHead[maxNumOfRules]; str *ruleCondition[maxNumOfRules]; str *ruleAction[maxNumOfRules]; str *ruleRecovery[maxNumOfRules];"
